package form.contactlist;
import java.util.Vector;
import javax.swing.JList;
@SuppressWarnings("serial")
public class ContactList extends JList{
	Vector<Contact> contacts=new Vector<Contact>();
	public ContactList(Vector<Contact> contacts){
		super(contacts);
		this.contacts=contacts;
		this.setCellRenderer(new ContactElement());
	}
	public ContactList(){
		super();
		this.setListData(contacts);
		this.setCellRenderer(new ContactElement());
	}
	public void addContact(Contact contact){
		int id=contacts.indexOf(contact);
		if(id!=-1){
			contacts.remove(contact);
			contacts.add(id,contact);
		}else contacts.add(contact);
	}
	public void setStatus(String nick,boolean isOnline){
		int id=contacts.indexOf(new Contact(nick,"",true));
		if(id==-1)return;
		contacts.elementAt(id).setOnline(isOnline);
	}
}